# 1.6 自动选取步长梯形法
def fx(x):
    return 2 / (1 + x ** 2)


a = 0
b = 1
e = 0.01
h = (b - a) / 2
n = 1
t1 = (fx(a) + fx(b)) * h
while(1):
    t0 = t1
    s = 0
    for k in range(1, n + 1):
        s += fx(a + (2 * k - 1) * h / n)
    t1 = t0 / 2 + s * h / n
    print(n, t0, t1)
    if (abs(t1 - t0) < 3 * e):
        print("T=%.5f" % t1)
        break
    n *= 2
